package cn.mesmile.juc.assist.countdownlatch;

import java.util.concurrent.CountDownLatch;

/**
 * @author zb
 * @date 2022/1/23 12:03
 * @Description  CountDownLatchDemo 同时执行
 */
public class CountDownLatchDemo2 {

    public static void main(String[] args) {
        countDownLatchDemo();
    }

    public static void countDownLatchDemo() {
        CountDownLatch countDownLatch = new CountDownLatch(1);
        int size = 3;
        for (int i = 1; i <= size; i++) {
            new Thread(() -> {
                try {
                    countDownLatch.await();
                    Thread.sleep(100);
                    System.out.println(System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            },"当前线程："+ i).start();
        // 减去 1,等待上面线程同时执行
        countDownLatch.countDown();
        }
    }
}
